<template>
  <!-- 添加爬虫作者模态框 -->
  <el-dialog
    :title="$t('dialog.title.create_author')"
    :visible.sync="DialogShow"
    width="50%"
    :before-close="closeDialog"
  >
    <span class="main"
      ><el-form
        ref="form"
        :label-position="labelPosition"
        label-width="110px"
        :model="form"
        inline
        :rules="rules"
      >
        <el-form-item :label="$t('dialog.form.name')" prop="name">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item :label="$t('dialog.form.tel')" prop="phone_number">
          <el-input v-model="form.phone_number"></el-input>
        </el-form-item>
        <el-form-item :label="$t('dialog.form.email')" prop="email">
          <el-input v-model="form.email"></el-input>
        </el-form-item>
      </el-form>
    </span>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeDialog">{{ $t("dialog.btn.cancel") }}</el-button>
      <el-button type="warning" plain @click="resetForm">{{
        $t("dialog.btn.reset")
      }}</el-button>
      <el-button type="primary" @click="addPersonnel" style="width: 200px">{{
        $t("dialog.btn.create")
      }}</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  props: ["DialogShow"],
  data() {
    return {
      labelPosition: "right",
      // 创建人员表单数据
      form: {
        id: "",
      },
      // 验证规则
      rules: {
        name: [
          {
            required: true,
            trigger: "blur",
            message: this.$t("dialog.message.name"),
          },
        ],
        phone_number: [
          {
            required: true,
            trigger: "blur",
            message: this.$t("dialog.message.tel"),
          },
        ],
        email: [
          {
            required: true,
            trigger: "blur",
            message: this.$t("dialog.message.email"),
          },
        ],
      },
    };
  },
  methods: {
    // 创建爬虫
    addPersonnel() {
      this.$refs.form.validate((valid) => {
        if (!valid) return;
        this.$http.post("/reptile/auth/create", this.form).then((res) => {
          if (res.status == 200) {
            this.$refs.form.resetFields();
            this.$message.success("Creating a successful!");
            this.closeDialog("1");
          } else {
            this.$message.error("Create a failure!");
          }
        });
      });
    },
    resetForm() {
      this.$refs.form.resetFields();
    },
    // 关闭弹出框
    closeDialog(t) {
      this.$emit("closeDialog", t);
    },
  },
};
</script>

<style lang='less' scoped>
</style>